﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AMing.Core.Extension;

namespace MusicPlayerPlus.Method.Data
{
    /// <summary>
    /// 本地数据存取
    /// </summary>
    public class LocaData
    {
        /// <summary>
        /// 保存的文件夹
        /// </summary>
        public const string FILEPATH_SAVE_FOLDER = "/Data";
        /// <summary>
        /// 读取数据
        /// </summary>
        /// <param name="fileName">文件名（不带路径拓展名）</param>
        /// <returns></returns>
        public static string ReadData(string fileName)
        {
            fileName = GetFilePath(fileName);
            return AMing.Core.IO.TextFile.TxtFileRead(fileName);
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="fileName">文件名（不带路径拓展名）</param>
        /// <param name="data">保存的数据</param>
        public static void SaveData(string fileName, string data)
        {
            fileName = GetFilePath(fileName);
            AMing.Core.IO.TextFile.TxtFileWrite(fileName, data);
        }
        /// <summary>
        /// 获取文件路径
        /// </summary>
        /// <param name="fileName">文件名（不带路径拓展名）</param>
        /// <returns></returns>
        private static string GetFilePath(string fileName)
        {
            fileName = fileName.Replace("/", "");
            fileName = fileName.Replace("\\", "");
            fileName = string.Format("{0}/{1}.mpd", FILEPATH_SAVE_FOLDER, fileName);
            return AMing.Core.IO.Path.GetApplicationPath(fileName);
        }
    }
}
